package com.avo.ramcache.util;

import com.avo.ramcache.config.IEntity;
import org.springframework.util.ReflectionUtils;

import java.lang.annotation.Annotation;
import java.lang.reflect.Field;
import java.util.ArrayList;
import java.util.List;

public class ReflectionUtil extends ReflectionUtils {

    public static Field[] getDeclaredFieldsWith(Class<IEntity<?>> clz, Class<? extends Annotation> anno) {
        List<Field> fields = new ArrayList<>();
        Field[] declaredFields = clz.getDeclaredFields();
        for (int i = 0; i < clz.getDeclaredFields().length; i++) {
            Field field = declaredFields[i];
            if (field.isAnnotationPresent(anno)) {
                fields.add(field);
            }
        }
        return fields.toArray(new Field[0]);
    }

}
